package cn.bdqn.component;



import cn.bdqn.controller.ChargeController;
import cn.bdqn.domain.Charge;
import cn.bdqn.domain.DoctorDiagnose;
import cn.bdqn.domain.Recipe;
import cn.bdqn.domain.Registration;
import cn.bdqn.service.DoctorDiagnoseService;
import cn.bdqn.service.RegistrationService;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.Date;


@Component
public class PMMQReceiveDirectHandel {
    @Autowired
    private RegistrationService registrationService;
    @Autowired
    private DoctorDiagnoseService doctorDiagnoseService;
    @Autowired
    private  ChargeController chargeController;
    @Autowired
    private RedisTemplate redisTemplate;
    @RabbitListener(queues = "PM-Queue")//监听队列
    @RabbitHandler//处理
    public void getRecipe(Recipe recipe){
        Charge charge = new Charge();
        BigDecimal  money =new BigDecimal(recipe.getDrugTotalprice());
        Registration registration= registrationService.queryById(recipe.getRegisId());
        DoctorDiagnose doctorDiagnose=doctorDiagnoseService.queryByRegisId(recipe.getRegisId());
        if(doctorDiagnose.getIsHospital()==0){
            charge.setType(1);
        }else if(doctorDiagnose.getIsHospital()==1){
            charge.setType(0);
        }
        charge.setMenberId(registration.getMenberId());
        charge.setPayInfo("处方信息"+recipe.getRezept()+",病因:"+recipe.getEtiology());
        charge.setPayTime(new Date());
        charge.setTotalMoney(money);
        String nurseCard = (String) redisTemplate.boundValueOps(8).get();
        charge.setNurseCard(nurseCard);
        charge.setPayStatus(0);
        System.out.println(charge);
        chargeController.addCharge(charge);
    }
}
